package com.supervision.manage.mapper.sqlprovider

import com.supervision.domain.bean.po.AdminSearchPO
import org.apache.commons.lang3.StringUtils
import org.apache.ibatis.jdbc.SqlBuilder.*

class AdminSqlProvider {

    fun getAdminList(param: HashMap<String, Any>): String {
        val po = param["po"] as AdminSearchPO
        val limitSql = param["limitSql"] as String?
        BEGIN()
        if (StringUtils.isEmpty(limitSql)) {
            SELECT("count(*)")
        } else {
            SELECT(" a.* ")
        }
        FROM("admin a")
        WHERE(" a.weight >= 0 ")
        if (po.type > 0) {
            WHERE(" a.type = #{po.type} ")
        }
        if (po.name.isNotEmpty()) {
            WHERE(" a.name like concat('%', #{po.name},'%') ")
        }

        ORDER_BY("a.id desc")
        return SQL() + StringUtils.defaultString(limitSql, StringUtils.EMPTY)
    }
}